package com.example.reschain.demo01.service.impl;

import com.example.reschain.demo01.entity.Order;
import com.example.reschain.demo01.service.OrderHandler;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author renyitong
 * @version 1.0.0
 * @createTime 2023年07月28日
 * @Description
 */
@Service
public class CheckStockHandler implements OrderHandler {

    private OrderHandler next;

    public CheckStockHandler(@Qualifier("checkAccountHandler") OrderHandler next) {
        this.next = next;
    }

    /**
     * 检查商品库存
     * @param order
     */
    @Override
    public void handler(Order order) {
       if (Objects.nonNull(order.getProductNums()) && order.getProductNums() >0){
           System.out.println("当前还留有库存.....");
           next.handler(order);
       }else {
           throw new RuntimeException("没库存啦....");
       }
    }
}
